--
-- File generated with SQLiteStudio v3.3.3 on Thu May 26 17:08:57 2022
--
-- Text encoding used: UTF-8
--
PRAGMA foreign_keys = off;
BEGIN TRANSACTION;

-- Table: posts
DROP TABLE IF EXISTS posts;
CREATE TABLE posts (id INTEGER PRIMARY KEY ASC ON CONFLICT FAIL AUTOINCREMENT NOT NULL ON CONFLICT FAIL, title VARCHAR (150) NOT NULL UNIQUE, html TEXT NOT NULL DEFAULT (''), markdown TEXT NOT NULL DEFAULT (''), tags VARCHAR (500) NOT NULL DEFAULT (''), language CHAR (2) NOT NULL DEFAULT ES, slug VARCHAR (350) NOT NULL DEFAULT (''), status VARCHAR (15) DEFAULT DRAFT CHECK (status IN ('DRAFT', 'PUBLISHED', 'SYNCHRONIZE')) NOT NULL, translation_id INT REFERENCES translations (id) ON DELETE RESTRICT ON UPDATE CASCADE NOT NULL DEFAULT (0), created_at DATETIME DEFAULT (CURRENT_TIMESTAMP) NOT NULL, updated_at DATETIME DEFAULT (CURRENT_TIMESTAMP));

-- Table: translations
DROP TABLE IF EXISTS translations;
CREATE TABLE translations (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, count INT DEFAULT (0) NOT NULL);

-- Trigger: before_upd
DROP TRIGGER IF EXISTS before_upd;
CREATE TRIGGER before_upd BEFORE UPDATE OF id, title, html, markdown, tags, language, slug, translation_id ON posts BEGIN UPDATE posts SET updated_at = DATETIME('NOW') WHERE id = OLD.id; END;

COMMIT TRANSACTION;
PRAGMA foreign_keys = on;
